﻿function CheckAll() {
    var b = false;
    b1 = RegCheck("txtUserName", "lbUserName");
    b2 = RegCheck("txtPwd1", "lbPwd1");
    b3 = RegCheck("txtPwd2", "lbPwd2");
    b4 = RegCheck("txtEmail", "lbEmail");
    if (b1&&b2&&b3&&b4)
        b = true;
    return b;
}

function CheckAllEdit() {
    var b = false;
    b4 = RegCheck("txtEmail", "lbEmail");
    if (b4)
        b = true;
    return b;
}

function CheckPwd() {
    var b = false;
    b1 = RegCheck("txtOldPwd", "lbOldPwd");
    b2 = RegCheck("txtPwd1", "lbPwd1");
    b3 = RegCheck("txtPwd2", "lbPwd2");
    if (b1 && b2 && b3)
        b = true;
    return b;
}

function ReSetPassword() {
    var b = false;
    b2 = RegCheck("txtPwd1", "lbPwd1");
    b3 = RegCheck("txtPwd2", "lbPwd2");
    if (b2 && b3)
        b = true;
    return b;
}

function CheckMemberEditInfo() {
    var b = false;
    b4 = RegCheck("txtEmail", "lbEmail");
    if (b4)
        b = true;
    return b;
}

function RetrievePassword() {
    var b = false;
    b1 = RegCheck("txtUserNameRetrievePwd", "lbUserName");
    b4 = RegCheck("txtEmail", "lbEmail");
    if (b1 && b4)
        b = true;
    return b;
}


function RegTipInfo(o1, msg) {
    document.getElementById(o1).innerHTML = "<img src='../images/reg-info.gif'width=18 height=18 align='absbottom'/> <font color='#ff6600'>" + msg + "</font>";
}

function RegCheck(o1, o2) {

    if (o1 == "txtUserNameRetrievePwd") {
        if (document.getElementById(o1).value == "") {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>会员账户不能为空．</font>";
            return false;
        }
        document.getElementById(o2).innerHTML = "<img src='../images/reg-ok.gif'width=18 height=18 align='absbottom'/>";
        return true;
    }
    if (o1 == "txtUserName") {
        if (document.getElementById(o1).value == "") {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>会员账户不能为空．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length < 2) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能少于2字符．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length > 20) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能超过给20字符．</font>";
            return false;
        }
        //Ajax验证是否重复
        if (IsUserNameExists(document.getElementById(o1).value) == 2) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>不允许使用该用户名，请重新填写．</font>";
            return false;
        }
        if (IsUserNameExists(document.getElementById(o1).value)==1) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>该会员账户已存在，请重新填写．</font>";
            return false;
        }
        //判断是否是邮箱
        if (IsValidEMail(document.getElementById(o1).value)) {
            document.getElementById("txtEmail").value = document.getElementById(o1).value;
        }
        document.getElementById(o2).innerHTML = "<img src='../images/reg-ok.gif'width=18 height=18 align='absbottom'/>";
        return true;
    }
    if (o1 == "txtOldPwd") {
        if (document.getElementById(o1).value == "") {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>旧密码不能为空．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length < 6) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能少于6个字符．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length > 20) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能超过给20字符．</font>";
            return false;
        }
        document.getElementById(o2).innerHTML = "<img src='../images/reg-ok.gif'width=18 height=18 align='absbottom'/>";
        return true;

    }

    if (o1 == "txtPwd1") {
        if (document.getElementById(o1).value == "") {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>密码不能为空．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length < 6) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能少于6个字符．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length > 20) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能超过给20字符．</font>";
            return false;
        }
        document.getElementById(o2).innerHTML = "<img src='../images/reg-ok.gif'width=18 height=18 align='absbottom'/>";
        return true;

    }

    if (o1 == "txtPwd2") {
        if (document.getElementById(o1).value == "") {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>确认密码不能为空．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length < 6) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能少于6个字符．</font>";
            return false;
        }
        if (document.getElementById(o1).value.length > 20) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>长度不能超过给20字符．</font>";
            return false;
        }
        if (document.getElementById(o1).value != document.getElementById("txtPwd1").value) {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>两次密码不一致．</font>";
            return false;
        }
        document.getElementById(o2).innerHTML = "<img src='../images/reg-ok.gif'width=18 height=18 align='absbottom'/>";
        return true;

    }
    if (o1 == "txtEmail") {
        if (document.getElementById(o1).value == "") {
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>EMail不能为空．</font>";
            return false;
        }

        if (!IsValidEMail(document.getElementById(o1).value)) {
            //alert(o2)
            document.getElementById(o2).innerHTML = "<img src='../images/reg-error.gif'width=18 height=18 align='absbottom'/> <font color='#ff0000'>EMail格式不正确．</font>";
            return false;
        }
        document.getElementById(o2).innerHTML = "<img src='../images/reg-ok.gif'width=18 height=18 align='absbottom'/>";
        return true;

    }
}

//增加会员账户是否重复验证  cyq @ 2009-3-22 
function IsUserNameExists(UserName) {
    doc = GetAjaxResponse("../Controls/validate_user.aspx?txtUserName=" + UserName);
    //alert(doc);
    if (doc == 2) {
        return 2;
    }
    else if (doc == 0) {
        return 0;
    }
    else {
        return 1;
    }
}